<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${base.dao.packagePath}.${base.dao.className}">


    <sql id="query_param">
        <trim prefix="where" prefixOverrides="and | or">
            <#if table.columns?exists>
                <#list table.columns as column>
                    <if test="${column.attrName?uncap_first} != null">
                        and ${column.columnName} = ${"#"}{${column.attrName?uncap_first}}
                    </if>
                </#list>
            </#if>
        </trim>
    </sql>

    <select id="listByPage" parameterType="hashmap" resultType="${base.entity.packagePath}.${base.entity.className}">
        select *
        from ${table.tableName}
        <include refid="query_param"/>
        order by id desc
        <if test="start != null and size != null">
            limit ${"#"}{start},${"#"}{size}
        </if>
    </select>

    <select id="listByPageCount" parameterType="hashmap" resultType="int">
        select count(*)
        from ${table.tableName}
        <include refid="query_param"/>
    </select>

</mapper>